﻿using System;
using System.Collections.Generic;

using IDAL.AuthModel;
using Model.AuthModel;
using Model.Base;
using DALFactory.AuthModel;
namespace BLL.AuthModel
{
    /// <summary>
    /// 通用组件，权限模型，业务层，管理成员
    /// </summary>
    public class StaffBLL
    {
        IStaff dal = DataAccess.CreateStaff();

        /// <summary>
        /// 新增成员
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="email"></param>
        /// <param name="isLock"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public int InsertStaff(string username, string password, string email, string isLock, out string message)
        {
            StaffInfo info = new StaffInfo();
            info.Username = username;
            info.Password = password;
            info.Email = email;
            info.IsLock = isLock;
            return dal.InsertStaff(info, out message);
        }

        /// <summary>
        /// 更新成员信息
        /// </summary>
        /// <param name="staffID"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="email"></param>
        /// <param name="isLock"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public bool UpdateStaff(int staffID, string username, string password, string email, string isLock, out string message)
        {
            StaffInfo info = new StaffInfo();
            info.StaffID = staffID;
            info.Username = username;
            info.Password = password;
            info.Email = email;
            info.IsLock = isLock;
            return dal.UpdateStaff(info, out message);
        }

        /// <summary>
        /// 根据编号获取
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public StaffInfo GetStaffByID(int id) 
        {
            return dal.GetStaffByID(id);
        }

        /// <summary>
        /// 管理员登录
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public StaffInfo StaffLogin(string userName) 
        {
            return dal.GetStaffByName(userName);
        }

        /// <summary>
        /// 后台管理员列表
        /// </summary>
        /// <param name="roleid"></param>
        /// <param name="key"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public IList<StaffInfo> BackList(string key, int pageIndex, int pageSize, out int recordCount)
        {
            BaseCondition condition = new BaseCondition();
            condition.KeyWord = key;
            condition.PageIndex = pageIndex;
            condition.PageSize = pageSize;
            condition.OrderBy = "AddTime DESC";
            return dal.ListStaff(condition, out recordCount);
        }
    }
}
